package Servlet;

import Bean.Page;
import Bean.Ticket;
import Dao.TicketDao;
import Service.TicketService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 张
 * Date: 2025-03-12
 * Time: 12:57
 */
//用户订单展示
@WebServlet("/TicketListServlet")
public class TicketListServlet extends HttpServlet {
    private TicketService ticketService = new TicketService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json;charset=utf8");
        int pageNo = Integer.parseInt(req.getParameter("pageNo"));
        int pageSize = 5;
        //先从session中获取登录用户的userId
        HttpSession session = req.getSession();
        String userId = (String) session.getAttribute("LoginUserId");
        //查询用户所有订单信息
        Page page = ticketService.selectByUserId(userId,pageNo,pageSize);
        System.out.println("[TicketListServlet] 查询的订单数据为 : " + page.getList().toString());
        System.out.println(page.getPageNo() + " " + page.getPageSize() + " " + page.getTotalPages());
        req.setAttribute("list",page.getList());
        req.setAttribute("box",page);
        req.getRequestDispatcher("user_ticket.jsp").forward(req,resp);
    }
}
